package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysConfigError;
import com.ruoyi.system.service.ISysConfigErrorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 故障配置Controller
 * 
 * @author ruoyi
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/system/configError")
public class SysConfigErrorController extends BaseController
{
    @Autowired
    private ISysConfigErrorService sysConfigErrorService;

    /**
     * 查询故障配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configError:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysConfigError sysConfigError)
    {
        startPage();
        List<SysConfigError> list = sysConfigErrorService.selectSysConfigErrorList(sysConfigError);
        return getDataTable(list);
    }

    /**
     * 导出故障配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configError:export')")
    @Log(title = "故障配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysConfigError sysConfigError)
    {
        List<SysConfigError> list = sysConfigErrorService.selectSysConfigErrorList(sysConfigError);
        ExcelUtil<SysConfigError> util = new ExcelUtil<SysConfigError>(SysConfigError.class);
        util.exportExcel(response, list, "故障配置数据");
    }

    /**
     * 获取故障配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:configError:query')")
    @GetMapping(value = "/{errorId}")
    public AjaxResult getInfo(@PathVariable("errorId") Long errorId)
    {
        return AjaxResult.success(sysConfigErrorService.selectSysConfigErrorByErrorId(errorId));
    }

    /**
     * 新增故障配置
     */
    @PreAuthorize("@ss.hasPermi('system:configError:add')")
    @Log(title = "故障配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysConfigError sysConfigError)
    {
        return toAjax(sysConfigErrorService.insertSysConfigError(sysConfigError));
    }

    /**
     * 修改故障配置
     */
    @PreAuthorize("@ss.hasPermi('system:configError:edit')")
    @Log(title = "故障配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysConfigError sysConfigError)
    {
        return toAjax(sysConfigErrorService.updateSysConfigError(sysConfigError));
    }

    /**
     * 删除故障配置
     */
    @PreAuthorize("@ss.hasPermi('system:configError:remove')")
    @Log(title = "故障配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{errorIds}")
    public AjaxResult remove(@PathVariable Long[] errorIds)
    {
        return toAjax(sysConfigErrorService.deleteSysConfigErrorByErrorIds(errorIds));
    }
}
